//
//  SecondViewController.m
//  07-界面通信
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"

@interface SecondViewController ()
@property (nonatomic , strong)UITextField *textField;
@property (nonatomic , strong)UIButton *btn;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, 200, 50)];
    _textField.backgroundColor = [UIColor yellowColor];
    _textField.text = _str;
    [self.view addSubview:_textField];
    self.btn = [UIButton buttonWithType:UIButtonTypeSystem];
    _btn.frame = CGRectMake(100, 100, 100, 50);
    [_btn setTitle:@"上一页" forState:UIControlStateNormal];
    [self.view addSubview:_btn];
    [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)clickBtn:(UIButton *)sender {
//    NSInteger count = self.navigationController.viewControllers.count;
//  FirstViewController *first =  self.navigationController.viewControllers[count - 2];
//    first.titleStr = _textField.text;
#pragma mark - 触发协议方法 (判断代理人存不存在, 判断签订delegate的类有没有实现协议方法)
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
       [self.delegate passValue:_textField.text]; 
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
